package cn.shyouchi.wuguanjia.android.widget;

import android.app.Activity;
import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.PopupWindow;
import android.widget.TextView;

import butterknife.BindView;
import butterknife.ButterKnife;
import cn.shyouchi.wuguanjia.android.R;
import cn.shyouchi.wuguanjia.android.ui.attendance.AttendanceEntity;

/**
 * Created by Eenie on 2016/11/29 at 17:49
 * Email: 472279981@qq.com
 * Des:
 */

public class CheckDetailPop extends PopupWindow {

    @BindView(R.id.tv_rank_title)
    TextView mTvRankTitle;
    @BindView(R.id.tv_rank_in_time)
    TextView mTvRankInTime;
    @BindView(R.id.tv_rank_in_state)
    TextView mTvRankInState;
    @BindView(R.id.tv_rank_in_addr)
    TextView mTvRankInAddr;
    @BindView(R.id.tv_rank_out_time)
    TextView mTvRankOutTime;
    @BindView(R.id.tv_rank_out_state)
    TextView mTvRankOutState;
    @BindView(R.id.tv_rank_out_addr)
    TextView mTvRankOutAddr;
    private View conentView;
    AttendanceEntity.ResultMessageBean bean;


    public CheckDetailPop(final Activity context, AttendanceEntity.ResultMessageBean bean) {
        LayoutInflater inflater = (LayoutInflater) context
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        conentView = inflater.inflate(R.layout.pop_attendance_rank_detail_layout, null);
        this.bean = bean;
        ButterKnife.bind(this, conentView);

        int h = context.getWindowManager().getDefaultDisplay().getHeight();
        int w = context.getWindowManager().getDefaultDisplay().getWidth();
        

        // 设置SelectPicPopupWindow的View
        this.setContentView(conentView);
        // 设置SelectPicPopupWindow弹出窗体的宽
        this.setWidth(w);
        // 设置SelectPicPopupWindow弹出窗体的高
        this.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);
        // 设置SelectPicPopupWindow弹出窗体可点击
        this.setFocusable(true);
        this.setOutsideTouchable(true);
        // 刷新状态
        this.update();
        // 实例化一个ColorDrawable颜色为半透明
        ColorDrawable dw = new ColorDrawable(0000000000);
        // 点back键和其他地方使其消失,设置了这个才能触发OnDismisslistener ，设置其他控件变化等操作
        this.setBackgroundDrawable(dw);
        // mPopupWindow.setAnimationStyle(android.R.style.Animation_Dialog);
        // 设置SelectPicPopupWindow弹出窗体动画效果
        //this.setAnimationStyle(R.style.AnimationPreview);


        mTvRankTitle.setText(String.format("考勤详情：%1s %2s - %3s", bean.getDay(), bean.getService().getStarttime().substring(0, 5), bean.getService().getEndtime().substring(0, 5)));
        mTvRankInTime.setText(String.format("上班时间：--:--"));
        mTvRankInState.setText(String.format("考勤情况：暂无"));
        mTvRankInAddr.setText(String.format("考勤地址：暂无"));

        if (bean.getCheckin() != null) {
            mTvRankInTime.setText(String.format("上班时间：%s", TextUtils.isEmpty(bean.getCheckin().getTime()) ? "--:--" : bean.getCheckin().getTime()));
            mTvRankInState.setText(String.format("考勤情况：%s", TextUtils.isEmpty(bean.getCheckin().getAttendance()) ? "暂无" : bean.getCheckin().getAttendance()));
            mTvRankInAddr.setText(String.format("考勤地址：%s", TextUtils.isEmpty(bean.getCheckin().getAddress()) ? "暂无" : bean.getCheckin().getAddress()));
        }


        mTvRankOutTime.setText(String.format("下班时间：--:--"));
        mTvRankOutState.setText(String.format("考勤情况：暂无"));
        mTvRankOutAddr.setText(String.format("考勤地址：暂无"));

        if (bean.getSignback() != null) {
            mTvRankOutTime.setText(String.format("下班时间：%s", TextUtils.isEmpty(bean.getSignback().getTime()) ? "--:--" : bean.getSignback().getTime()));
            mTvRankOutState.setText(String.format("考勤情况：%s", TextUtils.isEmpty(bean.getSignback().getAttendance()) ? "暂无" : bean.getSignback().getAttendance()));
            mTvRankOutAddr.setText(String.format("考勤地址：%s", TextUtils.isEmpty(bean.getSignback().getAddress()) ? "暂无" : bean.getSignback().getAddress()));
        }


    }


    public void showPopupWindow(View parent) {
        if (!this.isShowing()) {
            this.showAsDropDown(parent, parent.getLayoutParams().width / 2, 0);
        } else {
            this.dismiss();
        }
    }

}
